#include <ansi_c.h>
#define SIZE 6
#define nr 'n'
#define bl 'b'
#define ab ' '
#define x 'x'
void detection(char tab[SIZE][SIZE]);
char case_haut_gauche(char);
char case_haut_centre(char);   
char case_haut_droite(char);   
char case_milieu_gauche(char);   
char case_milieu_droite(char);   
char case_bas_gauche(char);   
char case_bas_cantre(char);   
char case_bas_droite(char);   
void main(void)
{
 int i;
 int j;
 int b=0;
 int n=0;
 char tab[SIZE][SIZE]={ {ab,ab,ab,ab,ab,ab},
 				 		{ab,ab,ab,ab,ab,ab}, 		 /*definition du plateau*/
 				 		{ab,ab,bl,nr,ab,ab}, 
 				 		{ab,ab,nr,bl,ab,ab}, 
						{ab,ab,ab,ab,ab,ab}, 
						{ab,ab,ab,ab,ab,ab}, 
 					  };
 for(i=0;i<SIZE;i++)				 /*placement des lignes et colonnes*/
 {									 /*premier temps \n caractere de retour a la ligne, pour chaque ligne*/
  printf("\n");
  for(j=0;j<SIZE;j++)				 /*ecriture de la ligne caractere par caractere*/
  {
   printf("\t%c",tab[i][j]);
   if(tab[i][j]==bl)
	   b=b+1;
   else if (tab[i][j]==nr)
	   n=n+1;
  }
 }
 printf("\n\n");
 printf("\npoint blanc :%d\t\tpoint noir :%d",b,n);
 detection(tab);
}
/*---------------------------------------------------------------------------------------------------------------------------*/ 
											/*FONCTION PRINCIPALE*/
void detection(char tab[SIZE][SIZE])
{
 int i;
 int j;
 int b=0;
 int n=0;
 for(i=0 ; i<SIZE ; i++)
 {
  for(j=0 ; j<SIZE ; j++)
  {															 /*condition autour du pion noir pour placer le pion blanc*/
   if(tab[i][j]==nr)
   {
	tab[i-1][j-1]=case_haut_gauche(tab[i-1][j-1]);
	tab[i-1][j]=case_haut_centre(tab[i-1][j]);   
	tab[i-1][j+1]=case_haut_droite(tab[i-1][j+1]);   
	tab[i][j-1]=case_milieu_gauche(tab[i][j-1]);   
	tab[i][j+1]=case_milieu_droite(tab[i][j+1]);   
	tab[i+1][j-1]=case_bas_gauche(tab[i+1][j-1]);   
	tab[i+1][j]=case_bas_cantre(tab[i+1][j]);   
	tab[i+1][j+1]=case_bas_droite(tab[i+1][j+1]);   
   }
  }
 }
/*---------------------------------------------------------------------------------------------------------------------------*/ 	   
  											   /*AFFICHAGE DU TABLEAU AVEC LES X EMPLACEMENTS*/
 for(i=0;i<SIZE;i++)				 /*placement des lignes et colonnes*/
 {									 /*premier temps \n caractere de retour a la ligne, pour chaque ligne*/
  printf("\n");
  for(j=0;j<SIZE;j++)				 /*ecriture de la ligne caractere par caractere*/
  {
   printf("\t%c",tab[i][j]);
   if(tab[i][j]==bl)
	   b=b+1;
   else if (tab[i][j]==nr)
	   n=n+1;
  }
 }
 printf("\n\n");
 printf("\npoint blanc :%d\t\tpoint noir :%d",b,n);
}
/*---------------------------------------------------------------------------------------------------------------------------*/ 
char case_haut_gauche(char caract)
{
 char tab[SIZE][SIZE]={ {ab,ab,ab,ab,ab,ab},
 				 		{ab,ab,ab,ab,ab,ab}, 		 /*definition du plateau*/
 				 		{ab,ab,bl,nr,ab,ab}, 
 				 		{ab,ab,nr,bl,ab,ab}, 
						{ab,ab,ab,ab,ab,ab}, 
						{ab,ab,ab,ab,ab,ab},
                      };
 if(caract==nr || caract==bl)
 {													  /*premiere condition, si il y a un pion noir ou blanc*/
 }
 else
 {
  caract= x;										  /*deuxieme condition,si il n'y a aucun pion aux alentour*/
 }   
 return caract;
}
/*---------------------------------------------------------------------------------------------------------------------------*/ 
char case_haut_centre(char caract)
{
 char tab[SIZE][SIZE]={ {ab,ab,ab,ab,ab,ab},
 				 		{ab,ab,ab,ab,ab,ab}, 		 /*definition du plateau*/
 				 		{ab,ab,bl,nr,ab,ab}, 
 				 		{ab,ab,nr,bl,ab,ab}, 
						{ab,ab,ab,ab,ab,ab}, 
						{ab,ab,ab,ab,ab,ab},
                      };
 if(caract==nr || caract==bl)
 {
 }
 else
 {
  caract= x;
 }   
 return caract;
}
/*---------------------------------------------------------------------------------------------------------------------------*/ 
char case_haut_droite(char caract)
{
 char tab[SIZE][SIZE]={ {ab,ab,ab,ab,ab,ab},
 				 		{ab,ab,ab,ab,ab,ab}, 		 /*definition du plateau*/
 				 		{ab,ab,bl,nr,ab,ab}, 
 				 		{ab,ab,nr,bl,ab,ab}, 
						{ab,ab,ab,ab,ab,ab}, 
						{ab,ab,ab,ab,ab,ab},
                      };
 if(caract==nr || caract==bl)
 {
 }
 else
 {
  caract= x;
 }   
 return caract;
}
/*---------------------------------------------------------------------------------------------------------------------------*/ 
char case_milieu_gauche(char caract)
{
 char tab[SIZE][SIZE]={ {ab,ab,ab,ab,ab,ab},
 				 		{ab,ab,ab,ab,ab,ab}, 		 /*definition du plateau*/
 				 		{ab,ab,bl,nr,ab,ab}, 
 				 		{ab,ab,nr,bl,ab,ab}, 
						{ab,ab,ab,ab,ab,ab}, 
						{ab,ab,ab,ab,ab,ab},
                      };
 if(caract==nr || caract==bl)
 {
 }
 else
 {
  caract= x;
 }   
 return caract;
}
/*---------------------------------------------------------------------------------------------------------------------------*/ 
char case_milieu_droite(char caract)
{
 char tab[SIZE][SIZE]={ {ab,ab,ab,ab,ab,ab},
 				 		{ab,ab,ab,ab,ab,ab}, 		 /*definition du plateau*/
 				 		{ab,ab,bl,nr,ab,ab}, 
 				 		{ab,ab,nr,bl,ab,ab}, 
						{ab,ab,ab,ab,ab,ab}, 
						{ab,ab,ab,ab,ab,ab},
                      };
 if(caract==nr || caract==bl)
 {
 }
 else
 {
  caract= x;
 }
  return caract;
}
/*---------------------------------------------------------------------------------------------------------------------------*/  
char case_bas_gauche(char caract)
{
 char tab[SIZE][SIZE]={ {ab,ab,ab,ab,ab,ab},
 				 		{ab,ab,ab,ab,ab,ab}, 		 /*definition du plateau*/
 				 		{ab,ab,bl,nr,ab,ab}, 
 				 		{ab,ab,nr,bl,ab,ab}, 
						{ab,ab,ab,ab,ab,ab}, 
						{ab,ab,ab,ab,ab,ab},
                      };
 if(caract==nr ||caract==bl)
 {
 }
 else
 {
  caract= x;
 }
 return caract;
}
/*---------------------------------------------------------------------------------------------------------------------------*/ 
char case_bas_cantre(char caract)
{
 char tab[SIZE][SIZE]={ {ab,ab,ab,ab,ab,ab},
 				 		{ab,ab,ab,ab,ab,ab}, 		 /*definition du plateau*/
 				 		{ab,ab,bl,nr,ab,ab}, 
 				 		{ab,ab,nr,bl,ab,ab}, 
						{ab,ab,ab,ab,ab,ab}, 
						{ab,ab,ab,ab,ab,ab},
                      };
 if(caract==nr || caract==bl)
 {
 }
 else
 {
  caract= x;
 }
 return caract;
}
/*---------------------------------------------------------------------------------------------------------------------------*/ 
char case_bas_droite(char caract)
{
 char tab[SIZE][SIZE]={ {ab,ab,ab,ab,ab,ab},
 				 		{ab,ab,ab,ab,ab,ab}, 		 /*definition du plateau*/
 				 		{ab,ab,bl,nr,ab,ab}, 
 				 		{ab,ab,nr,bl,ab,ab}, 
						{ab,ab,ab,ab,ab,ab}, 
						{ab,ab,ab,ab,ab,ab},
                      };
 if(caract==nr || caract==bl)
 {
 }
 else
 {
  caract= x;
 }
 return caract;
}


